HTML <audio> Autoplay
The autoplay attribute is used to start an audio file automatically.
Example: The example illustrates the HTML audio with the attribute autoplay.
HTML
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < meta name = "viewport" content = "width=device-width, initial-scale=1.0" > < title >HTML Audio</ title > </ head > < body > < div > < p >Audio Controls Autoplay</ p > <!-- audio tag starts here --> < audio controls autoplay> < source src = "testAudio.mp3" type = "audio/mpeg" > </ audio > <!-- audio tag ends here --> </ div > < div > < p >Audio Controls Autoplay Muted</ p > <!-- audio tag starts here --> < audio controls autoplay muted> < source src = "testAudio.mp3" type = "audio/mpeg" > </ audio > <!-- audio tag ends here --> </ div > < div > < p >Audio Controls Autoplay Loop</ p > <!-- audio tag starts here --> < audio controls autoplay loop> < source src = "testAudio.mp3" type = "audio/mpeg" > </ audio > <!-- audio tag ends here --> </ div > </ body > </ html > |
Output:
HTML Audio
The HTML Audio offers the <audio> element, that allows websites to provide background music, sound effects, or play any audio content required for the website and enhance the overall user experience. The element <source> is wrapped inside the <audio> element that defines the source of the audio files as a value of an attribute src.
Contact Us